package mi.payment.transaction.balance;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import lainey.ui.widget.TitleView;
import mi.payment.R;
import mi.payment.db.dao.PayDetail;
import mi.payment.transaction.AutoFinishActivity;
import mi.payment.utils.MoneyUtils;
import sunmi.payment.L3.L3BroadcastHelper;

/**
 * 余额查询 -- 结果页面
 */
public class BalanceResultActivity extends AutoFinishActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.transaction_balance_activity_result);
        initView();
    }

    private void initView() {
        String cardNumber = getIntent().getStringExtra("extra_cardNo");
        long intAmount = getIntent().getLongExtra("extra_amount", 0);
        PayDetail payDetail = (PayDetail) getIntent().getSerializableExtra("extra_payDetail");

        TitleView titleView = findViewById(R.id.title_view);
        titleView.setLeftImageVisibility(View.GONE);
        titleView.setCenterText(R.string.menu_query_balance);

        TextView tvBalance = findViewById(R.id.tv_balance);
        TextView tvCardNum = findViewById(R.id.tv_card_num);

        String card = hideCardNumber(cardNumber);
        tvCardNum.setText(card);

        String balance = MoneyUtils.longCent2DoubleMoneyStr(intAmount);
        tvBalance.setText(balance);

        findViewById(R.id.mb_ok).setOnClickListener(
                v -> {
                    L3BroadcastHelper.sendQueryBalanceBroadcast(mActivity, payDetail);
                    finish();
                }
        );
    }

    private String hideCardNumber(String value) {
        StringBuilder sb = new StringBuilder(value);
        sb.replace(6, sb.length() - 4, "******");
        return sb.toString();
    }

    public static void startAction(Context context, String cardNo, long amount, PayDetail payDetail) {
        Intent intent = new Intent(context, BalanceResultActivity.class);
        intent.putExtra("extra_cardNo", cardNo);
        intent.putExtra("extra_amount", amount);
        intent.putExtra("extra_payDetail", payDetail);
        context.startActivity(intent);
    }


}
